/**
 * 保安位置记录字段表
 */

const mongoose = require('mongoose')

let schema = new mongoose.Schema({
    //保安电话 , index: true
    phone: { type: String },
    //创建时间
    createDate: String,
    //学校组织id , index: true
    orgCode: { type: String },
    //这个组织id所属类型  1：学校  2：教委机构
    orgType: String,
    //扩展数据
    data: {
        "user": {
            "id": String,
            "username": String,
            "phone": String,
            "createDate": String,
            "updateDate": String,
            "dataStatus":String,
            "dataStatusString": String,
            "userDetail": Object
        },
        "location": {
            "buildingName": String,
            "streetNumber": String,
            "street": String,
            "district": String,
            "cityCode": String,
            "country": String,
            "address": String,
            "altitude":String,
            "direction": String,
            "speed": String,
            "longitude": String,
            "buildingId": String,
            "city": String,
            "province": String,
            "countryCode": String,
            "radius": String,
            "latitude": String
        }
    },
    //数据生成时间
    time: { type: Date, default: Date.now, index: { expireAfterSeconds: global.COM_CONFIG.securityPointExpires } }
});

schema.index({ phone: 1 });
schema.index({ orgCode: 1 });
schema.index({ 'data.location.longitude': 1 });
schema.index({ 'data.location.latitude': 1 });

module.exports = schema;